package atm.zhaz;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

public class LoginDisplay extends TwoFieldForm implements ActionListener {
	MainWindow mainWindow;

	MyClient client;

	public LoginDisplay(MyClient c) {
		super("User entity", "Login: ", "Password: ");
		client = c;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	public MainWindow getMainWindow() {
		if (mainWindow == null) {
			mainWindow = new MainWindow(client);
		}
		return mainWindow;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("OKoy")) {
			client.setUsername(login1.getText());
			client.setPassword(pass1.getText());
			if (client.auth()){
				setVisible(false);
				getMainWindow().setVisible(true);
				getMainWindow().setParent(this);
			}else{
				MessageWindow m = new MessageWindow(
						"Invalid Login or password!");
				m.setVisible(true);
			}
		}
	}

}
